let app = getApp();
var applet_park_api_url = app.globalData.applet_park_api_url;
const {
  requestDataparams
} = require('../../../utils/request.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    accountName:'',
    accountNumber:'',
    address:'',
    totalMoney:'',
    unit:'',
    Fee:'',

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    var that = this;
    if(options.accountName){
       that.setData({
         accountName:options.accountName
       })
    }
    if(options.accountNumber){
      that.setData({
        accountNumber:options.accountNumber
      })
   }
   if(options.address){
    that.setData({
      address:options.address
    })
  } 
  if(options.totalMoney){
    var fee = options.totalMoney.split('.')[0];
    
    that.setData({
      totalMoney:options.totalMoney,
      Fee:fee
    })
  } 
  if(options.unit){
    that.setData({
      unit:options.unit
    })
  } 
  },
  enterPay() {
    let that = this;
    var token = app.globalData.TOKEN || wx.getStorageSync('TOKEN');
    var openId = app.globalData.openId || wx.getStorageSync('OPENID');
    var nickName =app.globalData.nickName || wx.getStorageSync('nickName');
    wx.request({
      url: applet_park_api_url + '/api/unifiedOrder/createOrder',
      method: 'POST',
      header: {
        Authorization: token
      },
      data: {
        orderType: 9,
        openId: openId,
        totalMoney: that.data.Fee+'00',
        preMoney: 0,
        realityMoney: that.data.Fee+'00',
      },
      success(res2) {
        
        if (res2.data.code == 0) {

          
          
          
          
          wx.requestPayment({
            timeStamp: res2.data.data.timeStamp,
            nonceStr: res2.data.data.nonceStr,
            package: res2.data.data.prepay_id,
            signType: 'MD5',
            paySign: res2.data.data.sign,
            paySource: 1,
            success(res) {

              wx.showToast({
                title: '支付成功',
              })

              setTimeout(function() {
                wx.showToast({
                  title: '页面跳转中',
                })
                wx.navigateTo({
                  url: '../orderDetails_canteen/orderDetails_canteen?orderNo=' + that.data.orderNo,
                })
       
              }, 500);
            },
            fail(res3) {
              
            }
          })

        } else {
          wx.showToast({
            title: '网络异常',
          })
        }
      },
      fail(res) {
        wx.showToast({
          title: res.data,
        })
      }
    })
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})